package org.xg.dao;

import java.io.Serializable;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.xg.domain.IdEntity;

import com.googlecode.genericdao.dao.hibernate.GenericDAOImpl;

public abstract class BaseDao<T, ID extends Serializable> extends GenericDAOImpl<T, ID> {
	
	@Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }
	
	public Session getDBSession(){
		return this.getSession();
	}

	public SessionFactory getDBSessionFactory(){
		return this.getSessionFactory();
	}

	public void saveOrUpdate(T obj){
		IdEntity idvo=(IdEntity)obj;
		String id=idvo.getId();
		if(id==null || id.trim().equals("")){
			this._save(obj);
		}else{
			obj=this._merge(obj);
		}
	}
}